package com.wyzt.page.web;

import com.wyzt.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

@Controller
public class PageController {

    @Autowired
    private PageService pageService;

    @GetMapping("item/{id}.html")
    public String toItemPage(@PathVariable("id") Long spuId, Model model) {
        //准备模型数据
        Map<String, Object> modelMap = pageService.getGoodsDetails(spuId);
        model.addAllAttributes(modelMap);

        //异步创建该id的静态页
        if (pageService.createPath(spuId).exists()) {
            pageService.asyncCreateHtml(spuId);
        }
        //返回结果
        return "item";
    }
}
